﻿using Microsoft.EntityFrameworkCore;
using Sample.ConsoleApp.CodeFist.Sqlite.DbContexts;
using Sample.ConsoleApp.CodeFist.Sqlite.Entitys;

namespace Sample.ConsoleApp.CodeFist.Sqlite.Repositories;

internal class MyEntityRepository(MyDb1Context context) : IMyEntityRepository
{
    private readonly MyDb1Context _context = context ?? throw new ArgumentNullException(nameof(context));

    public async Task<string?> AddAsync(MyEntity entity)
    {
        await _context.MyEntitys.AddAsync(entity);

        await _context.SaveChangesAsync();

        return entity.Id;
    }

    public async Task<MyEntity?> GetAsync(string id)
    {
        return await _context.MyEntitys.FirstOrDefaultAsync(x => x.Id == id);
    }

    public async Task<List<MyEntity>> GetListAsync(List<string> ids)
    {
        return await _context.MyEntitys.Where(x => ids.Contains(x.Id)).ToListAsync();
    }

}
